package com.mahjong.server.component.logic.handler;

import org.apache.log4j.Logger;
import org.apache.mina.core.session.IoSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.mahjong.server.common.Common;
import com.mahjong.server.component.logic.main.KHMahjongAction;
import com.mahjong.server.mina.protocol.AbsMessageProtocol;
import com.mahjong.server.mina.protocol.DataBuf;
import com.mahjong.server.mina.protocol.MessageProtocol;

/**
 * 吃牌：当有多种吃法时由玩家选择用哪两张牌吃,需要调用这个
 * 
 * @author yougang
 * @date 2013-3-5 上午10:59:26
 * @Description 麻将请求
 */
@Component
@Scope("prototype")
public class ChiPaiReq extends MessageProtocol {

  private static final byte TAG=Common.Req;

  private static final short PROTOCOL_NUM=0x0109;

  private Logger log=Logger.getLogger(this.getClass());

  KHMahjongAction action=new KHMahjongAction();

  // 需要客户端传入的参数
  @SuppressWarnings("unused")
  private int playerId;

  @SuppressWarnings("unused")
  private String pai; // 当前打出的牌

  @SuppressWarnings("unused")
  private String upai1; // 玩家手中用来吃的牌1

  @SuppressWarnings("unused")
  private String upai2; // 玩家手中用来吃的牌2

  @Override
  public short getProtocolNum() {
    return PROTOCOL_NUM;
  }

  @Override
  public byte getTag() {
    return TAG;
  }

  @Override
  public AbsMessageProtocol execute(IoSession session, AbsMessageProtocol req) {
    log.debug(this.getClass().getSimpleName() + " execute");
    // 调用chi(String[] pais,String upai1,String upai2)方法，然后要同步到内存和玩家对象中
    return null;
  }

  @Override
  public void reqDecode(DataBuf buf) {
    log.debug(this.getClass().getSimpleName() + " decode");
    playerId=buf.getInt();
    pai=buf.getString();
    upai1=buf.getString();
    upai2=buf.getString();
  }
}
